package com.cskaoyan.wordmemorize.controller.app;

import com.cskaoyan.wordmemorize.auth.StpKit;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.admin.VocDTO;
import com.cskaoyan.wordmemorize.dto.app.DisplayBookVocDTO;
import com.cskaoyan.wordmemorize.dto.app.DisplayChapterDTO;
import com.cskaoyan.wordmemorize.request.AppVocPageRequest;
import com.cskaoyan.wordmemorize.service.VocService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user/voc")
public class VocDetailController {
    @Autowired
    VocService vocService;
    //查看单词详情
    @GetMapping("detail/{vocId}")
    public Result<VocDTO> getVocDetail(@PathVariable("vocId")Long vocId) {
        //获取当前登录的用户id
        Long userId = StpKit.USER.getLoginIdAsLong();
        VocDTO vocDetail = vocService.getVocDetail(vocId, userId);
        return Result.ok(vocDetail);
    }
    //获取书籍单词列表（无章节版本）
    @GetMapping("/book/display")
    public Result<PageDTO<DisplayBookVocDTO>> getDisplayBookVocsInfo(AppVocPageRequest pageRequest) {
        Long userId = StpKit.USER.getLoginIdAsLong();
        pageRequest.setUserId(userId+"");
        PageDTO<DisplayBookVocDTO> displayBookVocsInfo = vocService.getDisplayBookVocsInfo(pageRequest);
        return Result.ok(displayBookVocsInfo);
    }
    //获取书籍单词列表（有章节版本）
    @GetMapping("book/chapter/display")
    public Result<PageDTO<DisplayChapterDTO>> getDisplayBookChapterVocsInfo(AppVocPageRequest pageRequest) {
        Long userId = StpKit.USER.getLoginIdAsLong();
        pageRequest.setUserId(userId+"");
        PageDTO<DisplayChapterDTO> displayBookChapterVocsInfo = vocService.getDisplayBookChapterVocsInfo(pageRequest);
        return Result.ok(displayBookChapterVocsInfo);
    }

}
